<template>
  <div class="help">
    <div class="help-head">
      <div class="title">帮助文件</div>
      <div class="more" @click="showMore">更多 >></div>
    </div>
    <div class="help-body">
      <div class="help-item" v-for="item in helpArr.slice(0,3)"  @click="openHelpFileFn(item)">
        <div class="help-text" :title="item.name.length > 10 ? item.name : ''">
          {{ item.name }}
        </div>
      </div>
      <template v-if="isEmpty">
        <div class="empty-text">暂无数据</div>
      </template>
    </div>
    <el-dialog custom-class="custom-dialog"
      title="帮助文件"
      :visible.sync="dialogVisible"
      width="6.6rem">
      <div class="dialog-body dialog-help-body">
        <div class="dialog-help-ul">
          <div class="dialog-help-item" v-for="item in helpArr" @click="openHelpFileFn(item)"> {{item.name}} </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { getHelpWordApi } from "../api/myHome"
  export default {
    name: '',
    mixins: [],
    components: {
    },
    props: {
    },
    data () {
      return {
        sid: this._sid,
        dialogVisible: false,
        helpArr: [
          {
            "name": "测试222",
            "remark": "123",
            "bindid": "a8fc30d8-802d-442a-afe6-ef37919ae557"
          }
        ],
        isEmpty: false,
        portalUrl: this._portalUrl
      }
    },
    computed: {},
    watch: {},
    created () {},
    mounted () {
      this.getHelpWordFn()
    },
    methods: {
      showMore() {
        this.dialogVisible = true
      },
      openHelpFileFn(item) {
        console.log("item", item)
        console.log("this.portalUrl", this.portalUrl)
        let url = `/portal/r/w?sid=${this.sid}&cmd=portal.person.openhelpword&bindid=${item.bindid}`
        window.open(url)
      },
      getHelpWordFn() {
        getHelpWordApi(this.sid).then(res => {
          this.helpArr = []
          if(res.result == 'ok') {
            this.helpArr = res.data
            this.isEmpty = res.data.length < 1 ? true : false
          }
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  @import "../style/common.scss";
  .help {
    border-radius: $radius2;
    background-color: #f7f9fd;
    margin-top: 0.2rem;
    padding: $pad-insert;
    .help-head {
      display: flex;
      justify-content: space-between;
      .title {
        font-size: $small-size;
        font-weight: bold;
      }
      .more {
        cursor: pointer;
        color: #5181e6;
        font-size: $min-size;
        i {
          color: #5181e6;
        }
      }
    }
    .help-body {
      margin-top: 0.15rem;
      display: flex;
      height: 0.8rem;
      overflow: hidden;
      .help-item {
        cursor: pointer;
        text-align: left;
        width: 1.2rem;
        height: 0.8rem;
        margin-right: 0.28rem;
        background: url(../assets/img/myHome/fileBg.png) no-repeat;
        background-size: contain;
        font-size: $min-size;
        color: #fff;
        padding: 0.15rem;
        box-sizing: border-box;
        &:last-child {
          margin-right: 0;
        }
        .help-text {
          width: 0.75rem;
          height: 0.5rem;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
        }
      }
    }
  }

</style>
<style lang="scss">
  @import "../style/common.scss";
  .dialog-help-body {
    min-height: 4rem;
    .dialog-help-ul {
      display: flex;
      flex-wrap: wrap;
      margin-bottom: 0.3rem;
      padding: 0.1rem 0 0.25rem 0;
      .dialog-help-item {
        margin-bottom: 0.2rem;
        text-align: left;
        width: 1.2rem;
        height: 1rem;
        background: url(../assets/img/myHome/fileBg.png) no-repeat;
        background-size: contain;
        font-size: $min-size;
        color: #fff;
        padding: 0.2rem;
        box-sizing: border-box;
        margin-right: 0.2rem;
        overflow: hidden;
        &:nth-child(4n) {
          margin-right: 0;
        }
      }
    }
  }
</style>
